]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
panel: Use click gesture to trigger window dragging from panel
authorCarlos Garnacho <carlosg@gnome.org>
Wed, 8 Oct 2025 17:11:37 +0000 (19:11 +0200)
committerCarlos Garnacho <carlosg@gnome.org>
Tue, 20 Jan 2026 13:00:46 +0000 (14:00 +0100)
This gesture is set up on the target phase, in order to ensure only button
presses on the panel itself (and not actors within it) are handled as window
drags.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/4021>

js/ui/panel.js

index 5f5a3c5d896de35a77bb66166f7d95fe8a2115d1..d836107a8ffb2fd5db541eb3c7259f09cca6db7a 100644 (file)
@@ -451,8 +451,13 @@ class Panel extends St.Widget {
         this._rightBox = new St.BoxLayout({name: 'panelRight'});
         this.add_child(this._rightBox);
 
-        this.connect('button-press-event', this._onButtonPress.bind(this));
-        this.connect('touch-event', this._onTouchEvent.bind(this));
+        this._clickGesture = new Clutter.ClickGesture({
+            recognize_on_press: true,
+        });
+        this._clickGesture.connect(
+            'recognize', this._onWindowDragGestureRecognize.bind(this));
+        this.add_action_full(
+            'window-drag', Clutter.EventPhase.TARGET, this._clickGesture);
 
         Main.overview.connectObject('showing',
             () => this.add_style_pseudo_class('overview'),
@@ -542,43 +547,25 @@ class Panel extends St.Widget {
         this._rightBox.allocate(childBox);
     }
 
-    _tryDragWindow(event) {
+    _onWindowDragGestureRecognize() {
         if (Main.modalCount > 0)
-            return Clutter.EVENT_PROPAGATE;
+            return;
 
+        const event = this._clickGesture.get_point_event(0);
         const backend = global.stage.get_context().get_backend();
         const sprite = backend.get_sprite(global.stage, event);
 
-        const targetActor = global.stage.get_event_actor(event);
-        if (targetActor !== this)
-            return Clutter.EVENT_PROPAGATE;
-
-        const [x, y] = event.get_coords();
-        const dragWindow = this._getDraggableWindowForPosition(x);
+        const coords = this._clickGesture.get_coords_abs();
+        const dragWindow = this._getDraggableWindowForPosition(coords.x);
 
         if (!dragWindow)
-            return Clutter.EVENT_PROPAGATE;
+            return;
 
-        const positionHint = new Graphene.Point({x, y});
-        return dragWindow.begin_grab_op(
+        dragWindow.begin_grab_op(
             Meta.GrabOp.MOVING,
             sprite,
             event.get_time(),
-            positionHint) ? Clutter.EVENT_STOP : Clutter.EVENT_PROPAGATE;
-    }
-
-    _onButtonPress(actor, event) {
-        if (event.get_button() !== Clutter.BUTTON_PRIMARY)
-            return Clutter.EVENT_PROPAGATE;
-
-        return this._tryDragWindow(event);
-    }
-
-    _onTouchEvent(actor, event) {
-        if (event.type() !== Clutter.EventType.TOUCH_BEGIN)
-            return Clutter.EVENT_PROPAGATE;
-
-        return this._tryDragWindow(event);
+            coords);
     }
 
     vfunc_key_press_event(event) {